package com.stu.serive.impl;

import com.stu.Dto.ComplaintDTO;
import com.stu.Dto.DormitoryRepairDTO;
import com.stu.context.BaseContext;
import com.stu.mapper.DormitoryRepairMapper;
import com.stu.pojo.Complaint;
import com.stu.pojo.DormitoryRepair;
import com.stu.serive.DormitoryRepairService;
import com.stu.serive.aTService;
import com.stu.vo.ComplaintVo;
import com.stu.vo.DormitoryRepairVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class DormitoryRepairImpl implements DormitoryRepairService {

    @Autowired
    private DormitoryRepairMapper dormitoryRepairMapper;

    /**
     * 添加寝室维修信息
     * @param dormitoryRepairDTO
     */
    public void insertDormitoryRepair(DormitoryRepairDTO dormitoryRepairDTO) {
        //获取学生id
        Long currentId = BaseContext.getCurrentId();
        //创建实体
        DormitoryRepair dormitoryRepair = new DormitoryRepair();
        //赋值
        BeanUtils.copyProperties(dormitoryRepairDTO, dormitoryRepair);
        dormitoryRepair.setStuId(Math.toIntExact(currentId));
        dormitoryRepair.setRequestTime(LocalDateTime.now());
        //添加操作
        dormitoryRepairMapper.insertDormitoryRepair(dormitoryRepair);
    }

    /**
     * 查询寝室维修结果
     * @return
     */
    public List<DormitoryRepairVo> selectDormitoryRepair() {
        //获取学生id
        Long currentId = BaseContext.getCurrentId();
        //根据学生id查询 留校申请表和学生基础信息表 获取Vo数据
        List<DormitoryRepairVo> dormitoryRepairVoList = dormitoryRepairMapper.selectDormitoryRepair(currentId);

        //对审核状态进行判断
        for (DormitoryRepairVo dormitoryRepair : dormitoryRepairVoList) {
            if (dormitoryRepair.getReply() == null){
                dormitoryRepair.setReply("暂未回复");
            }
        }
        return dormitoryRepairVoList;

    }

    /**
     * 查询所有宿舍维修申请
     * @return
     */
    public List<DormitoryRepairVo> dormitoryRepairApplicationAll() {
        return dormitoryRepairMapper.dormitoryRepairApplicationAll();
    }
}
